package com.simple.datax;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.dubbo.common.logger.Logger;
import com.alibaba.dubbo.common.logger.LoggerFactory;
import com.simple.datax.flow.message.EcFlowMessage;
import com.simple.datax.flow.message.EcFlowMessageBody;
import com.simple.datax.flow.message.EcFlowMessageHead;
import com.simple.datax.flow.message.EcFlowRespMessage;
import com.simple.datax.flow.message.EcFlowRespMessageBody.ResponseActionResult;

/** 
 * @Title: StartService.java 
 * @Package com.simple.datax 
 * @Description: TODO(流程模块服务启动入口) 
 * @author tonney 
 * @date 2013-1-7 上午10:24:35 
 * @version V1.0 
 */
public class StartService {
	public Logger log = LoggerFactory.getLogger(this.getClass());
	private ApplicationContext ctx;
	private static final ReentrantLock serviceLock = new ReentrantLock();
	private static final Condition serviceEnd = serviceLock.newCondition();
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		StartService app = new StartService();
		app.init();
		app.waitNo();
	}
	
	private int init() {
		try {
//			String xml = ReadFileUtil.readFile();
			log.info("Programme Begin Process!");
//			ctx = new FileSystemXmlApplicationContext("conf/applicationContext.xml");
//			ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
			ctx = new ClassPathXmlApplicationContext("classpath:provider-dubbo.xml");
//			MessageServiceImpl messageServiceManager = (MessageServiceImpl)ctx.getBean("messageServiceManager");
//			messageServiceManager.service(xml);
			log.info("end init.");
		} catch (Exception e) {
			log.error("Programme Begin Error:" + e.toString());
		}
		return 0;
	}

	private void waitNo() {
		serviceLock.lock();
		try {
			serviceEnd.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		} finally {
			serviceLock.unlock();
		}
	}


}
